home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / u_man / cat1 / oawk.z / oawk
Encoding:
Text File  |  2002-10-03  |  7.7 KB  |  199 lines

  1.  
  2.  
  3.  
  4. ooooaaaawwwwkkkk((((1111))))                                                                ooooaaaawwwwkkkk((((1111))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      oawk - pattern scanning and processing language
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ooooaaaawwwwkkkk [ ----FFFFc ] [ prog ] [ parameters ] [ files ]
  13.  
  14. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  15.      _o_a_w_k scans each input _f_i_l_e for lines that match any of a set of patterns
  16.      specified in _p_r_o_g.  With each pattern in _p_r_o_g there can be an associated
  17.      action that will be performed when a line of a _f_i_l_e matches the pattern.
  18.      The set of patterns may appear literally as _p_r_o_g, or in a file specified
  19.      as ----ffff _f_i_l_e.  The _p_r_o_g string should be enclosed in single quotes ('''') to
  20.      protect it from the shell.
  21.  
  22.      _P_a_r_a_m_e_t_e_r_s, in the form x=...  y=...  etc., may be passed to _o_a_w_k.
  23.  
  24.      Files are read in order; if there are no files, the standard input is
  25.      read.  The filename ---- means the standard input.  Each line is matched
  26.      against the pattern portion of every pattern-action statement; the
  27.      associated action is performed for each matched pattern.
  28.  
  29.      An input line is made up of fields separated by white space.  (This
  30.      default can be changed by using FS; see below).  The fields are denoted
  31.      $$$$1111, $$$$2222, ...; $$$$0000 refers to the entire line.
  32.  
  33.      A pattern-action statement has the form:
  34.  
  35.           pattern { action }
  36.  
  37.      A missing action means print the line; a missing pattern always matches.
  38.      An action is a sequence of statements.  A statement can be one of the
  39.      following:
  40.  
  41.           if ( conditional ) statement [ else statement ]
  42.           while ( conditional ) statement
  43.           for ( expression ; conditional ; expression ) statement
  44.           break
  45.           continue
  46.           { [ statement ] ... }
  47.           variable = expression
  48.           print [ expression-list ] [ >expression ]
  49.           printf format [ , expression-list ] [ >expression ]
  50.           next # skip remaining patterns on this input line
  51.           exit # skip the rest of the input
  52.  
  53.      Statements are terminated by semicolons, new-lines, or right braces.  An
  54.      empty expression-list stands for the whole line.  Expressions take on
  55.      string or numeric values as appropriate, and are built using the
  56.      operators ++++, ----, ****, ////, %%%%, and concatenation (indicated by a blank).  The
  57.      CCCCoperators ++++++++, --------, ++++====, ----====, ****====, ////====, and %%%%==== are also available in
  58.      expressions.  Variables may be scalars, array elements (denoted x[i]) or
  59.      fields.  Variables are initialized to the null string.  Array subscripts
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ooooaaaawwwwkkkk((((1111))))                                                                ooooaaaawwwwkkkk((((1111))))
  71.  
  72.  
  73.  
  74.      may be any string, not necessarily numeric; this allows for a form of
  75.      associative memory.  String constants are quoted ("""").
  76.  
  77.      The _p_r_i_n_t statement prints its arguments on the standard output (or on a
  78.      file if >>>>_e_x_p_r is present), separated by the current output field
  79.      separator, and terminated by the output record separator.  The _p_r_i_n_t_f
  80.      statement formats its expression list according to the format (see
  81.      _p_r_i_n_t_f(3S)).
  82.  
  83.      The built-in function _l_e_n_g_t_h returns the length of its argument taken as
  84.      a string, or of the whole line if no argument.  There are also built-in
  85.      functions _e_x_p, _l_o_g, _s_q_r_t, and _i_n_t.  The last truncates its argument to an
  86.      integer; _s_u_b_s_t_r(_s, _m, _n) returns the _n-character substring of _s that
  87.      begins at position _m.  The function _s_p_r_i_n_t_f(_f_m_t, _e_x_p_r, _e_x_p_r, ...)
  88.      formats the expressions according to the _p_r_i_n_t_f(3S) format given by _f_m_t
  89.      and returns the resulting string.
  90.  
  91.      Patterns are arbitrary Boolean combinations ( !!!!, ||, &&&&&&&&, and parentheses)
  92.      of regular expressions and relational expressions.  Regular expressions
  93.      must be surrounded by slashes and are as in _e_g_r_e_p (see _g_r_e_p(1)).
  94.      Isolated regular expressions in a pattern apply to the entire line.
  95.      Regular expressions may also occur in relational expressions.  A pattern
  96.      may consist of two patterns separated by a comma; in this case, the
  97.      action is performed for all lines between an occurrence of the first
  98.      pattern and the next occurrence of the second.
  99.  
  100.      A relational expression is one of the following:
  101.  
  102.           expression matchop regular-expression
  103.           expression relop expression
  104.  
  105.      where a relop is any of the six relational operators in C, and a matchop
  106.      is either ~~~~ (for _c_o_n_t_a_i_n_s) or !!!!~~~~ (for _d_o_e_s _n_o_t _c_o_n_t_a_i_n).  A conditional
  107.      is an arithmetic expression, a relational expression, or a Boolean
  108.      combination of these.
  109.  
  110.      The special patterns BEGIN and END may be used to capture control before
  111.      the first input line is read and after the last.  BEGIN must be the first
  112.      pattern, END the last.
  113.  
  114.      A single character _c may be used to separate the fields by starting the
  115.      program with:
  116.  
  117.           BEGIN { FS = _c }
  118.  
  119.      or by using the ----FFFF_c option.
  120.  
  121.      Other variable names with special meanings include NF, the number of
  122.      fields in the current record; NR, the ordinal number of the current
  123.      record; FILENAME, the name of the current input file; OFS, the output
  124.      field separator (default blank); ORS, the output record separator
  125.      (default new-line); and OFMT, the output format for numbers (default
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ooooaaaawwwwkkkk((((1111))))                                                                ooooaaaawwwwkkkk((((1111))))
  137.  
  138.  
  139.  
  140.      %%%%....6666gggg).
  141.  
  142. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  143.      Print lines longer than 72 characters:
  144.  
  145.           length > 72
  146.  
  147.      Print first two fields in opposite order:
  148.  
  149.           { print $2, $1 }
  150.  
  151.      Add up first column, print sum and average:
  152.  
  153.                { s += $1 }
  154.           END  { print "sum is", s, " average is", s/NR }
  155.  
  156.      Print fields in reverse order:
  157.  
  158.           { for (i = NF; i > 0; --i) print $i }
  159.  
  160.      Print all lines between start/stop pairs:
  161.  
  162.           /start/, /stop/
  163.  
  164.      Print all lines whose first field is different from previous one:
  165.  
  166.           $1 != prev { print; prev = $1 }
  167.  
  168.      Print file, filling in page numbers starting at 5:
  169.  
  170.           /Page/ { $2 = n++; }
  171.                  { print }
  172.  
  173.           command line:  oawk -f program n=5 input
  174.  
  175. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  176.      awk(1), grep(1), lex(1), perl(1), sed(1), printf(3S).
  177.  
  178. BBBBUUUUGGGGSSSS
  179.      Input white space is not preserved on output if fields are involved.
  180.      There are no explicit conversions between numbers and strings.  To force
  181.      an expression to be treated as a number add 0 to it; to force it to be
  182.      treated as a string concatenate the null string ("""""""") to it.
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.